import 'package:flutter/material.dart';

class SearchBox extends StatelessWidget {
  final String hintText;
  final Color backgroundColor;
  final Color textFieldColor;
  final VoidCallback? onTap;
  final TextEditingController? controller;
  final Function(String)? onSubmitted;
  final bool readOnly;

  const SearchBox({
    Key? key,
    this.hintText = '搜索你想找的商品',
    this.backgroundColor = Colors.red,
    this.textFieldColor = Colors.white,
    this.onTap,
    this.controller,
    this.onSubmitted,
    this.readOnly = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
      color: backgroundColor,
      child: Container(
        height: 36.0,
        decoration: BoxDecoration(
          color: textFieldColor,
          borderRadius: BorderRadius.circular(18.0),
        ),
        child: TextField(
          controller: controller,
          readOnly: readOnly,
          onTap: onTap,
          onSubmitted: onSubmitted,
          textAlignVertical: TextAlignVertical.center,
          decoration: InputDecoration(
            hintText: hintText,
            hintStyle: TextStyle(
              color: Colors.grey[400],
              fontSize: 14.0,
            ),
            prefixIcon: const Icon(
              Icons.search,
              color: Colors.grey,
              size: 20.0,
            ),
            border: InputBorder.none,
            contentPadding: const EdgeInsets.symmetric(vertical: 8.0),
          ),
        ),
      ),
    );
  }
}